package com.nationart.backend.core.response;

import java.io.Serializable;
/**
 * 返回数据结构
 * @author Administrator
 *
 */
public class ResponseData implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	//默认成功代码
	public final static Integer DEFAULT_SUCCESS_CODE = 200;
	public final static String DEFAULT_SUCCESS_MESSAGE = "执行成功";
	
	public final static Integer DEFAULT_FAILURE_CODE = 500;
	public final static String DEFAULT_FAILURE_MESSAGE = "执行失败";
	// 业务执行是否成功
	private Boolean success;
	// 返回的代码
	private Integer code;

	// 返回消息
	private String message;

	// 返回的数据
	private Object data;

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Boolean getSuccess() {
		return success;
	}

	public void setSuccess(Boolean success) {
		this.success = success;
	}

	public ResponseData(Boolean success, Integer code, String message, Object data) {
		this.success = success;
		this.code = code;
		this.message = message;
		this.data = data;
	}

	/**
	 * 自定义业务执行成功的代码，消息
	 * @param code
	 * @param message
	 * @param data
	 * @return
	 */
	public static ResponseData successResponse(Integer code, String message, Object data) {
		return new ResponseData(true, code, message, data);
	}
	
	/**
	 * 使用默认的业务执行成功的代码，消息
	 * @param data
	 * @return
	 */
	public static ResponseData successResponse( Object data) {
		return new ResponseData(true, DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MESSAGE, data);
	}
	
	/**
	 * 自定义业务执行失败的代码，消息
	 * @param code
	 * @param message
	 * @param data
	 * @return
	 */
	public static ResponseData failResponse(Integer code, String message) {
		return new ResponseData(false, code, message, null);
	}
	
	/**
	 * 使用默认的代码和消息
	 * @return
	 */
	public static ResponseData failResponse() {
		return new ResponseData(false, DEFAULT_FAILURE_CODE, DEFAULT_FAILURE_MESSAGE, null);
	}
}
